package principle.inversion.dependencyTrans;

/**
 * @author shkstart
 * @create ${year}-${month}-${day}-${time}
 */
public class dependenyT {
    public static void main(String[] args) {
        //接口方式传递
        /*people people = new people();
        yellow yellow = new yellow();
        people.push(yellow);*/
        //构造方法传递
        /*yellow yellow = new yellow();
        people people = new people(yellow);
        people.push();*/
        //setter方法传递
        yellow yellow = new yellow();
        people people = new people();
        people.setShit(yellow);
        people.push();
    }
}
//依赖关系的三种传递
//1 接口    2 构造方法    3 setter方法
/*
//方式一
interface ahead{
    public void push(shit shit);//抽象方法，接收接口
}
interface shit {
    public String color(String str);
}
class yellow implements shit{
    @Override
    public String color(String str) {
        return "黄色的";
    }
}
class people implements ahead{
    public void push(shit shit){
        String col = shit.color("");
        System.out.println("推着"+col+"大便");
    }
}*/
//方式二
/*
interface ahead{
    public void push();
}
interface shit {
    public String color(String str);
}
class yellow implements shit{
    @Override
    public String color(String str) {
        return "黄色的";
    }
}
class people implements ahead{
    private shit shit;

    //构造器
    public people(shit shit) {
        this.shit = shit;
    }

    @Override
    public void push() {
        String col = shit.color("");
        System.out.println("推着"+col+"大便");
    }
}*/
//方式三
interface ahead{
    public void push();
    public void setShit(shit shit);
}
interface shit {
    public String color(String str);
}
class yellow implements shit{
    @Override
    public String color(String str) {
        return "黄色的";
    }
}
class people implements ahead {
    private shit shit;
    @Override
    public void setShit(shit shit) {
        this.shit = shit;
    }

    @Override
    public void push() {
        String col = shit.color("");
        System.out.println("推着" + col + "大便");
    }
}